import pygame


class person:
    def __init__(self, ai_settings, screen):
        self.screen = screen
        self.ai_settings = ai_settings
        self.image = pygame.image.load('picture/charter.bmp')  # 放图片
        self.image = pygame.transform.scale(self.image, (60, 100))
        self.health = 10
        self.g = 1  # 重力加速度
        self.vectory_y = 0
        self.frame = 0
        self.collide_delta = 0
        self.jump_delta = 6
        self.rect = self.image.get_rect()  # 获取图片的外接矩形
        self.screen_rect = screen.get_rect()
        self.rect.centerx = self.screen_rect.centerx
        self.movex = float(self.rect.centerx)  # movex为人物在水平面上的坐标
        self.rect.centery = self.screen_rect.centery  # movey为人物在竖直面上的坐标
        self.movey = float(self.rect.centery)
        self.rect.bottom = self.screen_rect.bottom
        self.move_right = False
        self.move_left = False

    def gravity(self):  # 模拟引力
        self.vectory_y += 6
        self.movey += self.vectory_y
        if self.movey > 900 and self.vectory_y >= 0:
            self.vectory_y = 0
            self.movey = 900

    def update(self):
        if self.move_right:
            self.movex += self.ai_settings.charter_speed_factory
        elif self.move_left:
            self.movex -= self.ai_settings.charter_speed_factory
        self.rect.centerx = self.movex
        self.rect.centery = self.movey

    def blitime(self):
        self.screen.blit(self.image, self.rect)
